package seeders

import (
	"fmt"
	"github.com/goravel/framework/facades"
	"goravel/app/models"
)

type SysUserSeeder struct{}

func (s *SysUserSeeder) Signature() string {
	return "SysUserSeeder"
}

func (s *SysUserSeeder) Run() (err error) {
	password, err := facades.Hash().Make("admin")
	if err != nil {
		fmt.Println(err)
		return err
	}
	sysUser := models.SysUser{
		Name:     "admin",
		Password: password,
		Email:    "admin@admin.com",
	}
	err = facades.Orm().Query().Create(&sysUser)
	if err != nil {
		return err
	}
	sysRoles := []models.SysRole{
		{
			Name:   "admin",
			Slug:   "admin",
			Remark: "超级管理员",
			Status: 1,
		},
		{
			Name:   "editor",
			Slug:   "editor",
			Remark: "编辑运营人员",
			Status: 1,
		},
	}
	err = facades.Orm().Query().Create(&sysRoles)
	return err
}
